package com.party.mobile.web.controller.integral;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.party.api.dto.wechat.requst.XcxQrCodeRequest;
import com.party.authorization.annotation.Authorization;
import com.party.authorization.manager.impl.RedisTokenManager;
import com.party.authorization.utils.Constant;
import com.party.common.paging.Page;
import com.party.common.utils.PartyCode;
import com.party.common.utils.StringUtils;
import com.party.core.exception.BusinessException;
import com.party.core.model.YesNoStatus;
import com.party.core.model.city.Area;
import com.party.core.model.commune.*;
import com.party.core.model.member.Member;
import com.party.core.model.member.MemberGroup;
import com.party.core.model.member.PartnerMember;
import com.party.core.model.member.ThirdPartyUser;
import com.party.core.model.wechatPlatform.WechatOpenMember;
import com.party.core.service.city.IAreaService;
import com.party.core.service.commune.*;
import com.party.core.service.cos.CosBizService;
import com.party.core.service.member.*;
import com.party.core.service.wechatPlatform.IWechatOpenMemberService;
import com.party.mobile.biz.currentUser.CurrentUserBizService;
import com.party.mobile.biz.file.FileBizService;
import com.party.mobile.biz.member.CIntegralBizToService;
import com.party.core.service.commune.impl.CMemberIntegralBizService;
import com.party.mobile.biz.member.MemberBizService;
import com.party.mobile.biz.verifyCode.VerifyCodeBizService;
import com.party.mobile.web.dto.AjaxResult;
import com.party.mobile.web.dto.login.output.CurrentUser;
import com.party.mobile.web.dto.login.output.MemberOutput;
import com.party.notify.notifyPush.officialPartner.IOfficialPartnerNotifySendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author: huangzequn
 * @Date: 2019/8/13 10:54
 * 行知公社个人名片控制器
 */
@Controller
@RequestMapping(value = "/integral")
public class IntegralController {

    protected static Logger logger = LoggerFactory.getLogger(IntegralController.class);

    @Autowired
    private IMemberService memberService;

    @Autowired
    private ICMemberInfoService cMemberInfoService;

    @Autowired
    private IPartnerMemberService partnerMemberService;

    @Autowired
    private ICIntegralItemService integralItemService;

    @Autowired
    private CurrentUserBizService currentUserBizService;

    @Autowired
    private VerifyCodeBizService verifyCodeBizService;

    @Autowired
    private IThirdPartyUserService thirdPartyUserService;

    @Autowired
    private RedisTokenManager redisTokenManager;

    @Autowired
    private MemberBizService memberBizService;

    @Autowired
    private FileBizService fileBizService;

    @Autowired
    private CosBizService cosBizService;
    @Autowired
    private ICUserIntegralService userIntegralService;
    @Autowired
    private ICIntegralTypeService integralTypeService;
    @Autowired
    private IAreaService areaService;
    @Autowired
    private ICmemberBizService cmemberBizService;
    @Autowired
    private ICMemberRecommendService memberRecommendService;
    @Autowired
    private IWechatOpenMemberService wechatOpenMemberService;
    @Autowired
    private IMemberGroupService memberGroupService;
    @Autowired
    private CIntegralBizToService integralBizToService;
    @Autowired
    private IOfficialPartnerNotifySendService officialPartnerNotifySendService;
    @Autowired
    private ICMemberIntegralBalanceLogService memberIntegralBalanceLogService;
    @Autowired
    private CMemberIntegralBizService memberIntegralBizService;


    //个人行动力
    public static Integer DATATYPE_PERSONAL_ACTIONFORCE = 1;
    //个人影响力
    public static Integer DATATYPE_PERSONAL_INFLUENCE = 2;
    //被推荐人行动力
    public static Integer DATATYPE_RECOMMENDED_ACTIONFORCE = 3;


    /**
     * @param memberInfo
     * @return
     * @Author hzq
     * @Description //修改行知公社 用户信息
     * @Date 11:02 2019/8/13
     **/
    @ResponseBody
    @Authorization
    @RequestMapping("updateMemberInfo")
    public AjaxResult updateMemberInfo(CMemberInfoInput memberInfo, HttpServletRequest request) {
        CurrentUser currentUser = currentUserBizService.getCurrentUser(request);
        try {
            Member member = memberService.get(currentUser.getId());
            if (null == member) {
                return AjaxResult.error(100, "修改行知公社用户信息异常");
            }
            if (StringUtils.isNotEmpty(memberInfo.getMobile())) {
                if (StringUtils.isEmpty(memberInfo.getVerifyCode())) {
                    return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "验证码为空");
                }
                boolean verifyResult = verifyCodeBizService.verify(memberInfo.getMobile(), memberInfo.getVerifyCode());
                if (!verifyResult) {
                    return AjaxResult.error(PartyCode.VERIFY_CODE_ERROR, "验证码错误");
                }
            }
            boolean find = cMemberInfoService.updateMemberInfo(member, memberInfo);
            if (find) {
                return AjaxResult.success();
            } else {
                return AjaxResult.error(100, "该手机号码已被绑定");
            }

        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改行知公社用户信息异常", e);
            return AjaxResult.error(100, "修改行知公社用户信息异常");
        }
    }


    /**
     * @param pmId partner_member这张表的主键id
     * @return
     * @Author hzq
     * @Description //行知公社名片查询
     * @Date 14:32 2019/8/13
     **/
    @ResponseBody
    @RequestMapping("getByMemberId")
    public AjaxResult getByMemberId(String pmId) {

        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(100, "机构用户关系为空异常");
            }
            Map<String, Object> mmp = new HashMap<>();

            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            if (null == mainOrg) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "主机构关系不存在");
            }
            if (!partnerMember.getId().equals(mainOrg.getId())) {
                mainOrg = partnerMember;
                mmp.put("branchPartnerId", mainOrg.getPartnerId());
            } else {
                mmp.put("partnerId", mainOrg.getPartnerId());
            }
            String newPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            Map<String, Object> map = new HashMap<>();

            //用户详细信息
            CMemberInfo memberInfo = cMemberInfoService.getByMemberId(partnerMember.getMemberId());

            if (null == memberInfo) {
                memberInfo = new CMemberInfo();
            }
            Member member = memberService.get(partnerMember.getMemberId());
            memberInfo.setMobile(member.getMobile());
            memberInfo.setRealname(member.getRealname());
            memberInfo.setLogo(member.getLogo());
            memberInfo.setBacklogo(member.getBacklogo());

            //用户批号
            memberInfo.setUserSerial(partnerMember.getUserSerial());

            //设置城市名字
            if (!Strings.isNullOrEmpty(member.getCity())) {
                Area area = areaService.get(member.getCity());
                if (null != area) {
                    Area pa = areaService.get(area.getParentId());
                    memberInfo.setCity(area.getId());
                    memberInfo.setCityName(area.getName());
                    memberInfo.setProvince(pa.getName());
                }
            }
            //设置地区名字
            if (!Strings.isNullOrEmpty(memberInfo.getDistrict())) {
                Area area = areaService.get(memberInfo.getDistrict());
                if (null != area) {
                    Area pa = areaService.get(memberInfo.getDistrict());
                    memberInfo.setDistrictName(pa.getName());
                }
            }
            memberInfo.setCity(member.getCity());
            memberInfo.setJobTitle(member.getJobTitle());
            memberInfo.setCompany(member.getCompany());
            memberInfo.setSex(member.getSex());
            memberInfo.setMemberId(member.getId());
            map.put("memberInfo", memberInfo);

            Double totalScore = 0d;
            //总积分
            totalScore = userIntegralService.getUserItemFractionSum(new CUserIntegral("", "", newPartnerId, partnerMember.getMemberId()));
            totalScore = totalScore == null ? 0d : totalScore;
            map.put("totalScore", totalScore);
            //个人资料二维码
            String filePath = fileBizService.getUploadCIPath(mainOrg.getPartnerId(), "integral");
            String url = cosBizService.getPreviewPictureUrl(filePath + mainOrg.getId());
            map.put("qrcodeUrl", url);
            //个人在该机构下的积分排行
            mmp.put("pmMemberId", mainOrg.getMemberId());
            mmp.put("cuiPartnerId", newPartnerId);
            CUserIntegralMobileOutput cUserIntegralMobileOutput = userIntegralService.queryUserIntegralMobile(mmp);
            map.put("ranking", cUserIntegralMobileOutput.getRanking());

            //所属机构
            MemberGroup memberGroup = memberGroupService.get(mainOrg.getPartnerId());
            //分社昵称
            map.put("partnerName", memberGroup.getRealname());

            return AjaxResult.success(map);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("行知公社名片查询异常", e);
            return AjaxResult.error(100, "行知公社名片查询异常");
        }
    }


    /**
     * @param pmId
     * @return
     * @Author hzq
     * @Description //积分详情列表
     * @Date 15:56 2019/8/13
     **/
    @ResponseBody
    //@Authorization
    @RequestMapping("list")
    public AjaxResult list(String pmId, String typeId, Page page) {
        Map<String, Object> map = new HashMap<>();
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构关系不存在");
            }
            String newPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            List<CIntegralItem> cIntegralItemList = integralItemService.getCIntegralItemsByPmIdAndTypeId(newPartnerId, typeId, partnerMember.getMemberId(), page);
            //总积分
            Double totalScore = userIntegralService.getUserItemFractionSum(new CUserIntegral("", typeId, newPartnerId, partnerMember.getMemberId()));
            map.put("totalScore", totalScore);
            map.put("cIntegralItemList", cIntegralItemList);
            return AjaxResult.success(map, page);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("积分详情列表异常", e);
            return AjaxResult.error(100, "积分详情列表异常");
        }
    }

    /**
     * @param pmId
     * @return
     * @Author hzq
     * @Description //积分详情列表
     * @Date 15:56 2019/8/13
     **/
    @ResponseBody
    //@Authorization
    @RequestMapping("listAll")
    public AjaxResult listAll(String pmId) {
        Map<String, Object> map = new HashMap<>();
        if (StringUtils.isEmpty(pmId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            String newPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            List<CIntegralItem> cIntegralItemList = integralItemService.getCIntegralItemsByPmId(newPartnerId, partnerMember.getMemberId());
            map.put("cIntegralItemList", cIntegralItemList);
            return AjaxResult.success(map);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("积分详情列表异常", e);
            return AjaxResult.error(100, "积分详情列表异常");
        }
    }


    /**
     * @param phone
     * @param verifyCode
     * @param request
     * @return
     * @Author hzq
     * @Description //绑定手机号码
     * @Date 14:20 2019/8/15
     **/
    @ResponseBody
    @Authorization
    @RequestMapping("bindPhoneNew")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public AjaxResult bindPhoneNew(String appId, String pmId, String phone, String verifyCode, Integer isRecommend, HttpServletRequest request) {
        if (StringUtils.isEmpty(phone) ||
                StringUtils.isEmpty(verifyCode) ||
                StringUtils.isEmpty(appId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            CurrentUser curUser = currentUserBizService.getCurrentUser(request);
            Member curMember = memberService.get(curUser.getId());
            boolean verifyResult = verifyCodeBizService.verify(phone, verifyCode);
            if (!verifyResult) {
                return AjaxResult.error(PartyCode.VERIFY_CODE_ERROR, "手机号和验证码不匹配");
            }
            //根据手机号查找用户
            Member mobileMember = memberService.findByPhone(phone, Member.MEMBER_PERSONAL);
            Map<String, Object> map = Maps.newHashMap();

            String partnerId = null;
            if (StringUtils.isNotEmpty(pmId)) {
                PartnerMember partnerMember = partnerMemberService.get(pmId);
                if (partnerMember == null) {
                    return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构信息不存在");
                } else {
                    partnerId = partnerMember.getPartnerId();
                }
            } else {
                MemberGroup xingZheGongSheMemberGroup = memberBizService.getXingZheGongSheMemberGroup();
                partnerId = xingZheGongSheMemberGroup.getId();
            }

            PartnerMember byPartnerAndMember = null;
            //若用户存在_说明是后台添加的用户或者是活动报名用户——  机构关系已存在
            if (null != mobileMember) {
                //当前用户不等于手机查到的用户
                if (!mobileMember.getId().equals(curMember.getId())) {
                    //手机查找到的用户是合作商账户，不允许合并
                    if (mobileMember.getIsPartner().equals(YesNoStatus.YES.getCode())) {
                        return AjaxResult.error(PartyCode.PHONE_EXIST, "该手机已被绑定，请确认");
                    }
                    List<ThirdPartyUser> thirdPartyUsers = thirdPartyUserService.get(null, mobileMember.getId(), appId);
                    if (thirdPartyUsers.size() > 0) {
                        return AjaxResult.error(PartyCode.PHONE_EXIST, "该手机已被绑定，请确认");
                    }
                    //如果当前用户是第三方授权账户
                    if (CurrentUser.isThirdparty(curUser)) {
                        //查找第三方表中当前用户的记录
                        List<ThirdPartyUser> tUsers = thirdPartyUserService.getByMemberId(curUser.getId());

                        if (null != tUsers && tUsers.size() > 0) {
                            //更新第三方表中当前用户的记录为手机号查询到的用户
                            for (ThirdPartyUser tUser : tUsers) {
                                tUser.setMemberId(mobileMember.getId());
                                thirdPartyUserService.update(tUser);
                            }
                        }

                        //更新登录用户信息
                        //删除token
                        String oldToken = request.getHeader(Constant.HTTP_HEADER_NAME);
                        redisTokenManager.delRelationshipByToken(oldToken);

                        //重新绑定token
                        String token = memberBizService.getToken(mobileMember);
                        map.put("token", token);
                        map.put("memberId", mobileMember.getId());


                        //绑定机构关系
                        HashMap<String, Object> param = Maps.newHashMap();
                        param.put("partnerId", partnerId);
                        param.put("memberId", mobileMember.getId());
                        List<PartnerMember> memberPartnersTo = partnerMemberService.getMemberPartnersTo(param);
                        if (memberPartnersTo.size() == 0) { //在partner的机构及其子机构下 没有查询到关系
                            byPartnerAndMember = new PartnerMember();
                            byPartnerAndMember.setMemberId(mobileMember.getId());
                            byPartnerAndMember.setPartnerId(partnerId);
                            PartnerMember mainOrg = partnerMemberService.getMainOrg(mobileMember.getId(), partnerId);
                            if (mainOrg == null) {
                                byPartnerAndMember.setPartnerType(PartnerMember.IS_MAIN_TYPE);
                            }
                            partnerMemberService.insert(byPartnerAndMember);
                        }
                    } else {
                        /**
                         * 不是第三方用户,此处不处理合并操作，
                         * 因为现机构账号是使用用户名密码登录的，若合并其他账号的手机，会使当前用户混乱
                         */
                        return AjaxResult.error(PartyCode.PHONE_EXIST, "该手机已被绑定，请确认");
                    }
                } else {
                    return AjaxResult.error(PartyCode.PHONE_BIND, "该手机已被绑定，请确认");
                }
            } else {//若用户不存在
                curMember.setMobile(phone);
                memberService.update(curMember);
                //机构关系
                PartnerMember byPartnerAndMember1 = partnerMemberService.findByPartnerAndMember(partnerId, curMember.getId());
                if (byPartnerAndMember1 == null) {
                    byPartnerAndMember = new PartnerMember();
                    byPartnerAndMember.setMemberId(curMember.getId());
                    byPartnerAndMember.setPartnerId(partnerId);

                    PartnerMember mainOrg = partnerMemberService.getMainOrg(curMember.getId(), partnerId);
                    if (null == mainOrg) {
                        byPartnerAndMember.setPartnerType(PartnerMember.IS_MAIN_TYPE);
                    }
                    partnerMemberService.insert(byPartnerAndMember);
                } else {
                    byPartnerAndMember = byPartnerAndMember1;
                }

                //邀请关系(0/null:不是通过邀请海报进入的，1：是)
                if (isRecommend != null && 1 == isRecommend) {
                    CMemberRecommend cMemberRecommend = new CMemberRecommend();
                    cMemberRecommend.setuId(byPartnerAndMember.getId());
                    cMemberRecommend.setParentId(pmId);
                    List<CMemberRecommend> list = memberRecommendService.list(cMemberRecommend);
                    if (list.size() == 0) {
                        memberRecommendService.insert(cMemberRecommend);
                    }
                }
                //审核状态
                CMemberInfo byMemberId = cMemberInfoService.getByMemberId(curMember.getId());
                if (byMemberId == null) {
                    byMemberId = new CMemberInfo();
                    byMemberId.setMemberId(curMember.getId());
                    byMemberId.setCheckStatus(CMemberInfo.CHECK_STATUS_AWAIT);
                    cMemberInfoService.insert(byMemberId);

                    try {
                        officialPartnerNotifySendService.xzgsNewMemberNotify(byPartnerAndMember.getMemberId(),
                                byPartnerAndMember.getPartnerId(), byPartnerAndMember.getId());
                    } catch (Exception e) {
                        logger.error("行知公社新会员加入消息通知异常", e);
                    }
                } else {
                    byMemberId.setCheckStatus(CMemberInfo.CHECK_STATUS_AWAIT);
                    cMemberInfoService.update(byMemberId);
                }
            }

            //获取主分社关系
            if (byPartnerAndMember == null) {
                if (mobileMember != null) {
                    byPartnerAndMember = partnerMemberService.getMainOrg(mobileMember.getId(), partnerId);
                } else {
                    byPartnerAndMember = partnerMemberService.getMainOrg(curMember.getId(), partnerId);
                }

            }
            //生成二维码
            integralBizToService.generateXZGSXCXQRCode(partnerId, curUser.getId());

            //如果当前用户有合并操作需重新赋值
            if (null != map.get("memberId") && !map.get("memberId").equals(curUser.getId())) {
                curUser = currentUserBizService.getCurrentUserByToken((String) map.get("token"));
            }
            Member dbMember = memberService.get(curUser.getId());
            Integer checkStatus = CMemberInfo.CHECK_STATUS_ADOPT;
            CMemberInfo byMemberId = cMemberInfoService.getByMemberId(curMember.getId());
            if (byMemberId != null) {
                checkStatus = byMemberId.getCheckStatus();
            }
            dbMember.setLogo(curMember.getLogo());
            dbMember.setBacklogo(curMember.getLogo());
            memberService.update(dbMember);
            MemberOutput memberOutput = memberBizService.getLoginMember(dbMember);
            memberOutput.setPmId(byPartnerAndMember.getId());
            memberOutput.setCheckStatus(checkStatus);
            return AjaxResult.success(memberOutput);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("绑定手机号码异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error(100, "绑定手机号码异常");
        }
    }

    /**
     * @param phone
     * @param verifyCode
     * @param request
     * @return
     * @Author hqh
     * @Description //绑定手机号码
     * @Date 14:20 2020/06/16
     **/
    @ResponseBody
    @Authorization
    @RequestMapping("partnerRecommend/bindPhone")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public AjaxResult recommendBindPhone(String appId, String partnerId, String phone, String verifyCode, HttpServletRequest request) {
        if (StringUtils.isEmpty(phone) ||
                StringUtils.isEmpty(verifyCode) ||
                StringUtils.isEmpty(partnerId) ||
                StringUtils.isEmpty(appId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            CurrentUser curUser = currentUserBizService.getCurrentUser(request);
            Member curMember = memberService.get(curUser.getId());
            boolean verifyResult = verifyCodeBizService.verify(phone, verifyCode);
            if (!verifyResult) {
                return AjaxResult.error(PartyCode.VERIFY_CODE_ERROR, "手机号和验证码不匹配");
            }
            //根据手机号查找用户
            Member mobileMember = memberService.findByPhone(phone, Member.MEMBER_PERSONAL);
            Map<String, Object> map = Maps.newHashMap();

            PartnerMember byPartnerAndMember = null;
            //若用户存在_说明是后台添加的用户或者是活动报名用户——  机构关系已存在
            if (null != mobileMember) {
                //当前用户不等于手机查到的用户
                if (!mobileMember.getId().equals(curMember.getId())) {
                    //手机查找到的用户是合作商账户，不允许合并
                    if (mobileMember.getIsPartner().equals(YesNoStatus.YES.getCode())) {
                        return AjaxResult.error(PartyCode.PHONE_EXIST, "该手机已被绑定，请确认");
                    }
                    List<ThirdPartyUser> thirdPartyUsers = thirdPartyUserService.get(null, mobileMember.getId(), appId);
                    if (thirdPartyUsers.size() > 0) {
                        return AjaxResult.error(PartyCode.PHONE_EXIST, "该手机已被绑定，请确认");
                    }
                    //如果当前用户是第三方授权账户
                    if (CurrentUser.isThirdparty(curUser)) {
                        //查找第三方表中当前用户的记录
                        List<ThirdPartyUser> tUsers = thirdPartyUserService.getByMemberId(curUser.getId());

                        if (null != tUsers && tUsers.size() > 0) {
                            //更新第三方表中当前用户的记录为手机号查询到的用户
                            for (ThirdPartyUser tUser : tUsers) {
                                tUser.setMemberId(mobileMember.getId());
                                thirdPartyUserService.update(tUser);
                            }
                        }

                        //更新登录用户信息
                        //删除token
                        String oldToken = request.getHeader(Constant.HTTP_HEADER_NAME);
                        redisTokenManager.delRelationshipByToken(oldToken);

                        //重新绑定token
                        String token = memberBizService.getToken(mobileMember);
                        map.put("token", token);
                        map.put("memberId", mobileMember.getId());


                        //绑定机构关系
                        HashMap<String, Object> param = Maps.newHashMap();
                        param.put("partnerId", partnerId);
                        param.put("memberId", mobileMember.getId());
                        List<PartnerMember> memberPartnersTo = partnerMemberService.getMemberPartnersTo(param);
                        if (memberPartnersTo.size() == 0) { //在partner的机构及其子机构下 没有查询到关系
                            byPartnerAndMember = new PartnerMember();
                            byPartnerAndMember.setMemberId(mobileMember.getId());
                            byPartnerAndMember.setPartnerId(partnerId);
                            byPartnerAndMember.setPartnerType(PartnerMember.IS_MAIN_TYPE);
                            PartnerMember mainOrg = partnerMemberService.getMainOrg(curMember.getId(), partnerId);
                            if (null != mainOrg) {
                                partnerMemberService.delete(mainOrg.getId());
                            }
                            partnerMemberService.insert(byPartnerAndMember);
                        }
                    } else {
                        /**
                         * 不是第三方用户,此处不处理合并操作，
                         * 因为现机构账号是使用用户名密码登录的，若合并其他账号的手机，会使当前用户混乱
                         */
                        return AjaxResult.error(PartyCode.PHONE_EXIST, "该手机已被绑定，请确认");
                    }
                } else {
                    return AjaxResult.error(PartyCode.PHONE_BIND, "该手机已被绑定，请确认");
                }
            } else {//若用户不存在
                curMember.setMobile(phone);
                memberService.update(curMember);
                //机构关系
                PartnerMember byPartnerAndMember1 = partnerMemberService.findByPartnerAndMember(partnerId, curMember.getId());
                if (byPartnerAndMember1 == null) {
                    byPartnerAndMember = new PartnerMember();
                    byPartnerAndMember.setMemberId(curMember.getId());
                    byPartnerAndMember.setPartnerId(partnerId);
                    byPartnerAndMember.setPartnerType(PartnerMember.IS_MAIN_TYPE);

                    PartnerMember mainOrg = partnerMemberService.getMainOrg(curMember.getId(), partnerId);
                    if (null != mainOrg) {
                        partnerMemberService.delete(mainOrg.getId());
                    }
                    partnerMemberService.insert(byPartnerAndMember);
                } else {
                    byPartnerAndMember = byPartnerAndMember1;
                }
                //审核状态
                CMemberInfo byMemberId = cMemberInfoService.getByMemberId(curMember.getId());
                if (byMemberId == null) {
                    byMemberId = new CMemberInfo();
                    byMemberId.setMemberId(curMember.getId());
                    byMemberId.setCheckStatus(CMemberInfo.CHECK_STATUS_AWAIT);
                    cMemberInfoService.insert(byMemberId);

                    try {
                        officialPartnerNotifySendService.xzgsNewMemberNotify(byPartnerAndMember.getMemberId(),
                                byPartnerAndMember.getPartnerId(), byPartnerAndMember.getId());
                    } catch (Exception e) {
                        logger.error("行知公社新会员加入消息通知异常", e);
                    }
                } else {
                    byMemberId.setCheckStatus(CMemberInfo.CHECK_STATUS_AWAIT);
                    cMemberInfoService.update(byMemberId);
                }
            }

            //获取主分社关系
            if (byPartnerAndMember == null) {
                if (mobileMember != null) {
                    byPartnerAndMember = partnerMemberService.getMainOrg(mobileMember.getId(), partnerId);
                } else {
                    byPartnerAndMember = partnerMemberService.getMainOrg(curMember.getId(), partnerId);
                }

            }
            //生成二维码
            integralBizToService.generateXZGSXCXQRCode(partnerId, curUser.getId());

            //如果当前用户有合并操作需重新赋值
            if (null != map.get("memberId") && !map.get("memberId").equals(curUser.getId())) {
                curUser = currentUserBizService.getCurrentUserByToken((String) map.get("token"));
            }
            Member dbMember = memberService.get(curUser.getId());
            Integer checkStatus = CMemberInfo.CHECK_STATUS_ADOPT;
            CMemberInfo byMemberId = cMemberInfoService.getByMemberId(curMember.getId());
            if (byMemberId != null) {
                checkStatus = byMemberId.getCheckStatus();
            }
            dbMember.setLogo(curMember.getLogo());
            dbMember.setBacklogo(curMember.getLogo());
            memberService.update(dbMember);
            MemberOutput memberOutput = memberBizService.getLoginMember(dbMember);
            memberOutput.setPmId(byPartnerAndMember.getId());
            memberOutput.setCheckStatus(checkStatus);
            return AjaxResult.success(memberOutput);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("绑定手机号码异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error(100, "绑定手机号码异常");
        }
    }

    /**
     * @Description：获取奖牌列表
     * @Param: [pmId, page]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/8/30
     */
    @ResponseBody
    /*    @Authorization*/
    @RequestMapping("queryMedallist")
    public AjaxResult queryMedallist(String pmId, Page page, HttpServletRequest request) {
        if (StringUtils.isEmpty(pmId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        List<CIntegralTypeOutput> objects = new ArrayList<>();
        Map<String, Object> mmp = new HashMap<>();
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构关系不存在");
            }
            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            if (null == mainOrg) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "主机构关系不存在");
            }
            if (!partnerMember.getId().equals(mainOrg.getId())) {
                mainOrg = partnerMember;
                mmp.put("branchPartnerId", mainOrg.getPartnerId());
            } else {
                mmp.put("partnerId", mainOrg.getPartnerId());
            }
            String cuiPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            objects = integralTypeService.queryMedalListByPmIdAndPartnerId(cuiPartnerId, cuiPartnerId, partnerMember.getMemberId(), page);


            mmp.put("pmMemberId", mainOrg.getMemberId());

            for (CIntegralTypeOutput citObj : objects) {
                Double totalScore = userIntegralService.getUserItemFractionSum(new CUserIntegral("", citObj.getId(), cuiPartnerId, partnerMember.getMemberId()));
                totalScore = totalScore == null ? 0 : totalScore;
                citObj.setFraction(totalScore);
                mmp.put("typeId", citObj.getId());
                mmp.put("cuiPartnerId", cuiPartnerId);
                CUserIntegralMobileOutput cUserIntegralMobileOutput = userIntegralService.queryUserIntegralMobile(mmp);
                citObj.setRanking(cUserIntegralMobileOutput.getRanking());
            }
            return AjaxResult.success(objects, page);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("获取奖牌列表异常", e);
            return AjaxResult.error(100, "获取奖牌列表异常");
        }
    }

    /**
     * @Description：获取机构下的用户积分排行榜
     * @Param: [pmId, page]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/8/30
     */
    @ResponseBody
    /*@Authorization*/
    @RequestMapping("queryUserIntegralRankingList")
    public AjaxResult queryUserIntegralRankingList(String pmId, Page page, Integer type, Integer timeType, String integralTypeId, String branchPartnerId,
                                                   HttpServletRequest request) {
        if (StringUtils.isEmpty(pmId) || null == type) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构关系不存在");
            }
            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            if (null == mainOrg) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "主机构关系不存在");
            }
            String newPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            List<CUserIntegralMobileOutput> cUserIntegralMobileOutputs = new ArrayList<>();

            List<String> orgIds = memberGroupService.getChildWithMy(newPartnerId);

            Map<String, Object> mmp = new HashMap<>();
            if (StringUtils.isEmpty(branchPartnerId)) {
                mmp.put("partnerId", mainOrg.getPartnerId());
            } else if (mainOrg.getPartnerId().equals(branchPartnerId)) {
                mmp.put("partnerId", mainOrg.getPartnerId());
            } else {
                //切换分社查看排名
                mmp.put("branchPartnerId", branchPartnerId);
            }

            mmp.put("cuiPartnerId", newPartnerId);
            memberBizService.appendParams(mmp, timeType, integralTypeId);

            if (DATATYPE_PERSONAL_ACTIONFORCE == type) {
                cUserIntegralMobileOutputs = userIntegralService.queryUserIntegralMobileList(mmp, page);
            } else if (DATATYPE_PERSONAL_INFLUENCE == type) {
                mmp.put("recommondOrgIds", orgIds);
                cUserIntegralMobileOutputs = userIntegralService.queryIntegralInfluenceRankingList(mmp, page);
            } else if (DATATYPE_RECOMMENDED_ACTIONFORCE == type) {
                mmp.put("isRecommend", true);
//                mmp.put("parentId", pmId);
                mmp.put("partnerId", null);
                mmp.put("recommondOrgIds", orgIds);
                mmp.put("cuiMemberId", partnerMember.getMemberId());
                cUserIntegralMobileOutputs = userIntegralService.queryUserIntegralMobileList(mmp, page);
            }
            return AjaxResult.success(cUserIntegralMobileOutputs, page);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("获取机构下的用户积分排行榜异常", e);
            return AjaxResult.error(100, "获取机构下的用户积分排行榜异常");
        }
    }


    /***
     * 获取机构下的积分类型
     * @Date 14:12 2019/10/15
     * @param pmId
     * @return
     **/
    @ResponseBody
    @RequestMapping("queryUserIntegralTypesList")
    public AjaxResult queryUserIntegralTypesList(String pmId, HttpServletRequest request) {
        if (StringUtils.isEmpty(pmId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构关系不存在");
            }

            String partnerId = partnerMember.getPartnerId();
            //积分类型是主账号维护的，查主账号的所有积分类型
            MemberGroup memberGroup = memberGroupService.get(partnerId);
            if (memberGroup.getPartnerId() != null) {
                partnerId = memberGroup.getPartnerId();
            }
            //当前机构下的积分类型
            List<CIntegralType> cIntegralTypes = integralTypeService.getAllTypes(partnerId);
            return AjaxResult.success(cIntegralTypes);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("获取机构下的用户积分类型异常", e);
            return AjaxResult.error(100, "获取机构下的用户积分类型异常");
        }
    }

    /**
     * @Description：获取机构下的用户积分排行榜
     * @Param: [pmId, page]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/8/30
     */
    @ResponseBody
    /*    @Authorization*/
    @RequestMapping("queryUserIntegralRanking")
    public AjaxResult queryUserIntegralRanking(String pmId, Integer type, Integer timeType, String integralTypeId, String branchPartnerId,
                                               HttpServletRequest request) {
        if (StringUtils.isEmpty(pmId) || type == null) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构关系不存在");
            }
            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            if (null == mainOrg) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "主机构关系不存在");
            }
            String newPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            List<String> orgIds = memberGroupService.getChildWithMy(newPartnerId);

            Map<String, Object> mmp = new HashMap<>();
            if (StringUtils.isEmpty(branchPartnerId) || mainOrg.getPartnerId().equals(branchPartnerId)) {
                mmp.put("partnerId", mainOrg.getPartnerId());
            } else {
                //切换分社查看排名
                mmp.put("branchPartnerId", branchPartnerId);
            }
            mmp.put("pmMemberId", mainOrg.getMemberId());
            mmp.put("cuiPartnerId", newPartnerId);
            mmp.put("recommondOrgIds", orgIds);
            memberBizService.appendParams(mmp, timeType, integralTypeId);
            CUserIntegralMobileOutput cUserIntegralMobileOutput = null;
            //1:个人行动力，2：个人影响力
            if (1 == type) {
                cUserIntegralMobileOutput = userIntegralService.queryUserIntegralMobile(mmp);
            } else if (2 == type) {
                cUserIntegralMobileOutput = userIntegralService.queryIntegralInfluenceRanking(mmp);
            }
            return AjaxResult.success(cUserIntegralMobileOutput);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("获取机构下的用户积分排行榜异常", e);
            return AjaxResult.error(100, "获取机构下的用户积分排行榜异常");
        }
    }

    /**
     * @Description: 查询当前用户审核状态
     * @Param: [request]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/10/30
     */
    @ResponseBody
    @Authorization
    @RequestMapping("queryUserCheckStatus")
    public AjaxResult queryUserCheckStatus(HttpServletRequest request) {
        try {
            CurrentUser curUser = currentUserBizService.getCurrentUser(request);
            CMemberInfo byMemberId = cMemberInfoService.getByMemberId(curUser.getId());
            Integer checkStatus = 3;
            if (byMemberId != null) {
                checkStatus = byMemberId.getCheckStatus();
            }
            return AjaxResult.success(checkStatus);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询当前用户审核状态异常", e);
            return AjaxResult.error(100, "查询当前用户审核状态异常");
        }
    }


    /***
     * 获取会员所属分社
     * @Date 15:51 2019/11/18
     * @param pmId
     * @return
     **/
    @ResponseBody
    @RequestMapping("member/partnersList")
    public AjaxResult getMemberPartners(String pmId) {
        if (StringUtils.isEmpty(pmId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            //会员主分社
            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            String partnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());

            List<MemberGroup> orgIds = memberGroupService.getChildWithMyAndName(partnerId);
            List<MemberGroup> memberGroupList = new ArrayList<>();
            for (MemberGroup orgId : orgIds) {
                PartnerMember byPartnerAndMember = partnerMemberService.findByPartnerAndMember(orgId.getId(), partnerMember.getMemberId());
                if (byPartnerAndMember != null) {
                    memberGroupList.add(orgId);
                }
            }
            int mainNum = 0;
            //获取主分社在集合中的位置
            for (int i = 0; i < memberGroupList.size(); i++) {
                if (mainOrg.getPartnerId().equals(memberGroupList.get(i).getId())) {
                    mainNum = i;
                }
            }
            if (mainNum != 0) {
                MemberGroup firstMemberGroup = memberGroupList.get(0);
                memberGroupList.set(0, memberGroupList.get(mainNum));
                memberGroupList.set(mainNum, firstMemberGroup);
            }

            return AjaxResult.success(memberGroupList);
        } catch (Exception e) {
            logger.error("获取会员所属分社失败", e);
            return AjaxResult.error(100, "获取会员所属分社失败");
        }
    }

    /**
     * @Description: 获取小程序二维码
     * @Param: [pmId]
     * @return: com.party.web.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/8/15
     */
    @ResponseBody
    @RequestMapping("/checkXcxQrCode")
    public AjaxResult checkXcxQrCode(String pmId, Integer type) {
        if (StringUtils.isEmpty(pmId) || (type == null || type == 0)) {
            return AjaxResult.error(100, "参数不能为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(100, "partnerMember对象为空");
            }
            HashMap<Integer, String> mmp = Maps.newHashMap();
            //个人资料邀请二维码
            mmp.put(1, "integral");
            //海报邀请二维码
            mmp.put(2, "integralRecommend");

            //获取主账号关系
            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            if (mainOrg == null) {
                return AjaxResult.error(100, "主账号关系对象为空");
            }

            //生成二维码
            WechatOpenMember openMember = wechatOpenMemberService.findByType(com.party.common.constant.Constant.WECHAT_ACCOUNT_TYPE_SYSTEM_XCX_INTEGRAL);
            //生成推荐海报小程序码
            String tagUrl = mmp.get(type);
            if (StringUtils.isEmpty(tagUrl)) {
                return AjaxResult.error(100, "获取小程序二维码图片异常 pmId:" + pmId + ", type:" + type);
            }
            XcxQrCodeRequest qrCodeRequest = new XcxQrCodeRequest();
            if (1 == type) {
                qrCodeRequest.setPage("pages/card/index");
            }
            if (2 == type) {
                qrCodeRequest.setPage("pages/slogin/index");
            }
            qrCodeRequest.setScene(mainOrg.getId());
            String filePath = fileBizService.getUploadCIPath(mainOrg.getPartnerId(), tagUrl);
            String result = fileBizService.uploadCloudOutXcs(mainOrg.getId(), filePath, qrCodeRequest, openMember.getAuthorizerAccessToken(), 1);
            return AjaxResult.success("200", result);
        } catch (Exception e) {
            logger.error("生成小程序码异常", e);
            return AjaxResult.error(100, e.getMessage());
        }
    }

    /**
     * @Description：获取奖牌列表
     * @Param: [pmId, page]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/8/30
     */
    @ResponseBody
    /*    @Authorization*/
    @RequestMapping("new/queryMedallist")
    public AjaxResult queryMedallist2(String pmId, Page page, HttpServletRequest request) {
        if (StringUtils.isEmpty(pmId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        List<CIntegralTypeOutput> objects = new ArrayList<>();
        Map<String, Object> mmp = new HashMap<>();
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);
            if (null == partnerMember) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "机构关系不存在");
            }
            PartnerMember mainOrg = partnerMemberService.getMainOrg(partnerMember.getMemberId(), partnerMember.getPartnerId());
            if (null == mainOrg) {
                return AjaxResult.error(PartyCode.DATA_UNEXIST, "主机构关系不存在");
            }
            if (!partnerMember.getId().equals(mainOrg.getId())) {
                mainOrg = partnerMember;
                mmp.put("branchPartnerId", mainOrg.getPartnerId());
            } else {
                mmp.put("partnerId", mainOrg.getPartnerId());
            }
            String cuiPartnerId = memberGroupService.getPartnerId(partnerMember.getPartnerId());
            objects = integralTypeService.queryMedalListByPmIdAndPartnerId2(cuiPartnerId, cuiPartnerId, partnerMember.getMemberId(), page);


            mmp.put("pmMemberId", mainOrg.getMemberId());

            for (CIntegralTypeOutput citObj : objects) {
                Double totalScore = userIntegralService.getUserItemFractionSum(new CUserIntegral("", citObj.getId(), cuiPartnerId, partnerMember.getMemberId()));
                totalScore = totalScore == null ? 0 : totalScore;
                citObj.setFraction(totalScore);
                mmp.put("typeId", citObj.getId());
                mmp.put("cuiPartnerId", cuiPartnerId);
                CUserIntegralMobileOutput cUserIntegralMobileOutput = userIntegralService.queryUserIntegralMobile(mmp);
                citObj.setRanking(cUserIntegralMobileOutput.getRanking());
            }
            return AjaxResult.success(objects, page);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("获取奖牌列表异常", e);
            return AjaxResult.error(100, "获取奖牌列表异常");
        }
    }

    /**
     * @Description: 获取邀请人
     * @Param: [request]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/10/30
     */
    @ResponseBody
    //@Authorization
    @RequestMapping("getRecommendMember")
    public AjaxResult getRecommendMember(String pmId, HttpServletRequest request) {
        try {
            Map<String, Object> mmp = new HashMap<>();
            CMemberRecommend cMemberRecommend = new CMemberRecommend();
            cMemberRecommend.setuId(pmId);
            List<CMemberRecommend> list = memberRecommendService.list(cMemberRecommend);
            if (list.size() > 0) {
                CMemberRecommend cmrOrg = list.get(0);
                PartnerMember partnerMember = partnerMemberService.get(cmrOrg.getParentId());
                if (partnerMember != null) {
                    Member member = memberService.get(partnerMember.getMemberId());
                    if (member != null) {
                        mmp.put("pmId", partnerMember.getId());
                        mmp.put("recommendDate", cmrOrg.getCreateDate());
                        mmp.put("memberName", member.getRealname());
                        mmp.put("memberLogo", member.getLogo());
                    }
                }
            }
            return AjaxResult.success(mmp);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("获取邀请人异常", e);
            return AjaxResult.error(100, "获取邀请人异常");
        }
    }

    /**
     * @Description: 用户积分维护
     * @Param: [request]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/10/30
     */
    @ResponseBody
    @RequestMapping("userIntegralMaintain")
    public AjaxResult userIntegralMaintain() {
        try {
            memberIntegralBizService.refreshCMemberIntegralBalanceLog(null);
            return AjaxResult.success();
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("用户积分维护异常", e);
            return AjaxResult.error(100, "用户积分维护异常");
        }
    }

    /**
     * @Description: 用户积分统计维护
     * @Param: [request]
     * @return: com.party.mobile.web.dto.AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/10/30
     */
    @ResponseBody
    @RequestMapping("userIntegralCountMaintain")
    public AjaxResult userIntegralCountMaintain() {
        try {
            memberIntegralBizService.refreshCMemberIntegralCount(null);
            return AjaxResult.success();
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("用户积分统计维护异常", e);
            return AjaxResult.error(100, "用户积分统计维护异常");
        }
    }

    /**
     * mvn
     *
     * @param pmId
     * @return
     * @Author hzq
     * @Description //积分详情列表
     * @Date 15:56 2019/8/13
     **/
    @ResponseBody
    //@Authorization
    @RequestMapping("v2/listAll")
    public AjaxResult listAll2(String pmId) {
        Map<String, Object> map = new HashMap<>();
        if (StringUtils.isEmpty(pmId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "参数为空");
        }
        try {
            PartnerMember partnerMember = partnerMemberService.get(pmId);

            Map<String, Object> params = Maps.newHashMap();
            params.put("partnerId", partnerMember.getPartnerId());
            params.put("memberId", partnerMember.getMemberId());
            List<IntegralItemInfoOutput> cIntegralItemList = memberIntegralBalanceLogService.getCMemberIntegralBalanceLogs(params, null);
            map.put("cIntegralItemList", cIntegralItemList);
            return AjaxResult.success(map);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("积分详情列表异常", e);
            return AjaxResult.error(100, "积分详情列表异常");
        }
    }
}
